package filters;

import interfaces.IMap;

public class BigBlurFilter implements IFilter
{
	
	float SMap[][];
	public BigBlurFilter()
	{
		
        
        SMap = new float[5] [5];
        SMap[0] [0] = 1;
        SMap[1] [0] = 4;
        SMap[2] [0] = 6;
        SMap[3] [0] = 4;
        SMap[4] [0] = 1;

        SMap[0] [1] = 4;
        SMap[1] [1] = 16;
        SMap[2] [1] = 24;
        SMap[3] [1] = 16;
        SMap[4] [1] = 4;
        
        SMap[0] [2] = 6;
        SMap[1] [2] = 24;
        SMap[2] [2] = 36;
        SMap[3] [2] = 24;
        SMap[4] [2] = 6;
        
        SMap[0] [3] = 4;
        SMap[1] [3] = 16;
        SMap[2] [3] = 24;
        SMap[3] [3] = 16;
        SMap[4] [3] = 4;
        
        SMap[0] [4] = 1;
        SMap[1] [4] = 4;
        SMap[2] [4] = 6;
        SMap[3] [4] = 4;
        SMap[4] [4] = 1;
	}
	@Override
	public int ApplyFilter(int Px,int Py, IMap map) 
	{
		int sum=0;
		for (int y = -2; y < 3; y++)
            for (int x = -2; x < 3; x++)
            {
            	int xf=x + 2;
            	int yf=y + 2;
            	float C = map.Get(Px + x,Py + y);
            	sum += (int)(C * SMap[xf][yf]);
            	
            }
		sum=sum/256;
		if (sum > 255)
            return 255;
        if (sum < 0)
            return 0;
        return sum;
	}

}
